﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class control_Reply : System.Web.UI.UserControl
{
    const int starNumber = 5;
    /// <summary>
    /// 评论和回复的状态
    /// </summary>
    public enum ReplyState
    {
        //评价对方
        noComment,
        beforeComment,
        afterCommentBeforReplied,
        afterReplied,
        //被对方评价
        beforeCommented,
        afterCommentedBeforeReply,
        afterReply
    }

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    //当前状态
    ReplyState currentState;
    //设置回复状态
    public void setState(ReplyState state)
    {
        currentState = state;
        switch (state)
        {
            case ReplyState.noComment:
                {
                    setTitle("无法评论");

                    score.Visible = false;
                    star.Visible = false;

                    comment.Visible = false;
                    text1.Visible = false;
                    textBox1.Visible = false;
                    button1.Visible = false;

                    reply.Visible = false;
                    text2.Visible = false;
                    textBox2.Visible = false;
                    button2.Visible = false;

                    break;
                }
            case ReplyState.beforeComment:
                {
                    setTitle("请评论");
                    this.setScore(-1); ;

                    score.Visible = true;
                    star.Visible = true;
                    this.star.initial(5, 0, false);

                    comment.Visible = true;
                    text1.Visible = false;
                    textBox1.Visible = true;
                    button1.Visible = true;

                    reply.Visible = false;
                    text2.Visible = false;
                    textBox2.Visible = false;
                    button2.Visible = false;

                    break;
                }
            case ReplyState.afterCommentBeforReplied:
                {
                    setTitle("我的评论");
                    score.Visible = true;
                    star.Visible = true;

                    comment.Visible = true;
                    text1.Visible = true;
                    textBox1.Visible = false;
                    button1.Visible = false;

                    reply.Visible = false;
                    text2.Visible = false;
                    textBox2.Visible = false;
                    button2.Visible = false;

                    break;
                }
            case ReplyState.afterReplied:
                {
                    setTitle("对方的回复");
                    score.Visible = true;
                    star.Visible = true;

                    comment.Visible = true;
                    text1.Visible = true;
                    textBox1.Visible = false;
                    button1.Visible = false;

                    reply.Visible = true;
                    text2.Visible = true;
                    textBox2.Visible = false;
                    button2.Visible = false;

                    break;
                }
            case ReplyState.beforeCommented:
                {
                    setTitle("对方尚未评论");
                    score.Visible = false;
                    star.Visible = false;

                    comment.Visible = false;
                    text1.Visible = false;
                    textBox1.Visible = false;
                    button1.Visible = false;

                    reply.Visible = false;
                    text2.Visible = false;
                    textBox2.Visible = false;
                    button2.Visible = false;

                    break;
                }
            case ReplyState.afterCommentedBeforeReply:
                {
                    setTitle("请回复对方的评论");
                    score.Visible = true;
                    star.Visible = true;

                    comment.Visible = true;
                    text1.Visible = true;
                    textBox1.Visible = false;
                    button1.Visible = false;

                    reply.Visible = true;
                    text2.Visible = false;
                    textBox2.Visible = true;
                    button2.Visible = true;

                    break;
                }
            case ReplyState.afterReply:
                {
                    setTitle("对对方的评论的回复");
                    score.Visible = true;
                    star.Visible = true;

                    comment.Visible = true;
                    text1.Visible = true;
                    textBox1.Visible = false;
                    button1.Visible = false;

                    reply.Visible = true;
                    text2.Visible = true;
                    textBox2.Visible = false;
                    button2.Visible = false;

                    break;
                }
        }
    }
    //获得当前状态
    public ReplyState getState()
    {
        return currentState;
    }

    //设置提示
    public void setTitle(String s)
    {
        this.title.Text = s;
    }
    //设置分数
    public void setScore(int score)
    {
        if (score <= 0)
        {
            //设置为未打分状态
            this.star.initial(starNumber, 0, false);
        }
        else
        {
            this.star.initial(starNumber, score, true);
        }
    }
    //获得分数
    public int getScore()
    {
        return star.Score;
    }

    //评论和回复
    public String Comment
    {
        get { return textBox1.Text; }
        set { text1.Text = value; }
    }
    public String Reply
    {
        get { return textBox2.Text; }
        set { text2.Text = value; }
    }

    #region 事件处理
    // ImageButtonClick事件处理函数类型
    public delegate void ImageButtonClickHandler(object sender, EventArgs e);
    // ImageButtonClick事件
    public event ImageButtonClickHandler imageButtonClick;
    protected void imageButton_Click(object sender, ImageClickEventArgs e)
    {
        imageButtonClick(this, null);
    }

    // button1Click事件处理函数类型
    public delegate void Button1ClickHandler(object sender, EventArgs e);
    // button1Click事件
    public event Button1ClickHandler button1ClickEvent;
    protected void button1_Click(object sender, EventArgs e)
    {
        button1ClickEvent(this, null);
    }

    // button2Click事件处理函数类型
    public delegate void Button2ClickHandler(object sender, EventArgs e);
    // button2Click事件
    public event Button2ClickHandler button2ClickEvent;
    protected void button2_Click(object sender, EventArgs e)
    {
        button2ClickEvent(this, null);
    }
    #endregion
}
